<%
	UserService userService = UserServiceFactory.getUserService();
	User user = (User) request.getAttribute("user");
	
	if (user == null) {
		response.sendRedirect("/atomfilter");
	}
%>

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<%@page import="com.google.appengine.api.users.User"%>


<%@page import="java.util.List"%>
<%@page import="sk.sodik.atomFilter.feeds.FeedFilter"%>
<%@page import="com.google.appengine.api.users.UserServiceFactory"%>
<%@page import="com.google.appengine.api.users.UserService"%>

<%@page import="sk.sodik.atomFilter.feeds.FeedFilterId"%><html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<script type="text/javascript" src="script.js"></script>
	<title>AtomFilter</title>
</head>
<body>
	Hello <%=user.getNickname()%> 
	<a href="<%=userService.createLogoutURL("/atomfilter")%>"> logout</a>
	<hr/>
	Your feeds:
	<table>
	<%
		List<FeedFilter> list = (List<FeedFilter>) request.getAttribute("feedList");
			for(FeedFilter entry : list) {
	%>
	<tr>
		<td> 
			<form action="/atomfilter" method="post"> 
				<input type="hidden" name="key" value="<%= entry.getKey() %>"/>
				<input type="hidden" name="action" value="del"/>
				<input type = "submit" value="delete"/>
			</form>
			<a href="#" onclick="fillAddForm('<%= entry.name + "','" + entry.url + "','" + entry.filter %>')">modify</a>
		</td>
		<td> <%= entry.name %> </td>
		<td> <%= entry.url %> </td>
		<td> <%= entry.filter %> </td>
		<% String key = request.getScheme()+ "://" + request.getServerName() +":" + request.getServerPort() 
			+"/feed/" + FeedFilterId.urlEncode(entry.getKey()); %>
		<td> <a href="<%= key %>"> <%= key %> </a> </td>
	</tr>
	
	<% } %>
	</table>
	
	<hr/>
	
	Add/modify feed filter: <br/>
	
	<form name="formular" action="/atomfilter" method="post">
		Name : <input type="text" name="name"/> <br/>
		Feed url: <input type="text" name="url"/> <br/>
		Feed filter: <input type="text" name="filter"/> <br/>
		<input type="hidden" name="action" value="add"/>
		<input type = "submit"/>
	</form>
	
</body>
</html>